<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        积分列表
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../backstage/css/x-admin.css" media="all">
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>会员管理</cite></a>
            <a><cite>积分管理</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="x-body">
        <form class="layui-form x-center" action="" style="width:800px">
            <div class="layui-form-pane" style="margin-top: 15px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">日期范围</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" name="beginCreateDate"placeholder="开始日期" id="LAY_demorange_s">
                    </div>
                    <div class="layui-input-inline">
                        <input class="layui-input" name="endCreateDate"placeholder="截止日期" id="LAY_demorange_e">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" id="username"name="username" placeholder="请输入用户名" autocomplete="off"
                               class="layui-input" maxlength="10">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" id="id" name="id" placeholder="请输入ID" autocomplete="off" class="layui-input"
                               maxlength="10" onkeyup="value=this.value.replace(/\D+/g,'')">
                    </div>
                    <div class="layui-input-inline" id="search"style="width:80px">
                        <input type="button"  class="layui-btn"  lay-submit="" lay-filter="sreach" value="搜索">
                        </input>
                    </div>
                </div>
            </div>
        </form>

        <div id="block">


            <%--<button class="layui-btn" onclick="kiss_add('添加积分','${path}/admin/creditAdd','','500','500')">--%>
                <%--<i class="layui-icon">&#xe608;</i>添加用户积分--%>
            <%--</button>--%>
            <%--<button class="layui-btn layui-btn-warm" onclick="kiss_delete('删除积分','${path}/admin/creditDelete','','500','500')">--%>
                <%--<i class="layui-icon">&#xe640;</i>删除积分--%>
            <%--</button>--%>
        </div>

        <table class="layui-table">
            <thead>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>性别</th>
                <th>创建时间</th>
                <th>角色</th>
                <th>积分</th>
                <th>更新时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="user_tbody">
            <tr>
            </tr>
            </tbody>
        </table>
        <div id="page" style="margin-left: 650px;"></div>

    </div>

    <script src="../../../backstage/js/jquery.min.js"></script>
    <script src="../../../backstage/lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../backstage/js/x-layui.js" charset="utf-8"></script>
    <script>
        layui.use(['element', 'layer'], function() {
            $ = layui.jquery; //jquery
            lement = layui.element(); //面包导航
            layer = layui.layer; //弹出层

            var start = {
                min: '1099-06-16 23:59:59',
                max: '2099-06-16 23:59:59',
                istoday: false,
                choose: function(datas) {
                    end.min = datas;
                    end.start = datas;
                }
            };
            var end = {
                min: '1099-06-16 23:59:59',
                max: '2099-06-16 23:59:59',
                istoday: false,
                choose: function(datas) {
                    start.max = datas;
                }
            };
            document.getElementById('LAY_demorange_s').onclick = function() {
                start.elem = this;
                laydate(start);
            };
            document.getElementById('LAY_demorange_e').onclick = function() {
                end.elem = this;
                laydate(end);
            };


            $("#search").click(function() {
                var uid = $.trim($("#id").val());
                var username = $.trim($("#username").val());
                var beginCreateDate = $.trim($("#LAY_demorange_s").val());
                var endCreateDate = $.trim($("#LAY_demorange_e").val());

                $.ajax({
                    type: 'POST',
                    url: '/userManager/selectElasticly',
                    dataType: "json",
                    data: {
                        uid: uid,
                        username: username,
                        sex: null, role: null,
                        state: null,
                        beginCreateDate: beginCreateDate,
                        endCreateDate: endCreateDate,
                        beginUpdateDate: null,
                        endUpdateDate: null
                    },
                    error: function () {
                        alert("查询失败");
                    },
                    success: function (data) {

                        console.info(JSON.stringify(data));
                        var str = '';
                        for (i = 0; i < data.length; i++) {
                            var user = data[i];
                            if(user.role!="管理员"&&user.role!="客服") {
                                str += '<tr>';
                                str += '  <td>' + user.id + '</td>';
                                str += '  <td>' + user.username + '</td>';
                                str += '  <td>' + user.sex + '</td>';
                                str += '  <td>' + new Date(user.createDate).toLocaleDateString().replace(/\//g, "-") + " " + new Date(user.createDate).toTimeString().substr(0, 8) + '</td>';
                                str += '  <td>' + user.role + '</td>';
                                str += '  <td>' + user.credit + '</td>';
                                str += '  <td>' + new Date(user.updateDate).toLocaleDateString().replace(/\//g, "-") + " " + new Date(user.updateDate).toTimeString().substr(0, 8) + '</td>';
                                str += '  <td>' + user.state + '</td>';
                                str += '  <td class="td-manage"> <button id="add" class="layui-btn layui-btn-danger" onclick="kiss_add(this)" data-id=' + user.id + '><i class="layui-icon">&#xe608;</i>添加用户积分</button><button id="delete" class="layui-btn layui-btn-warm" onclick="kiss_delete(this)"  data-id=' + user.id + '> <i class="layui-icon">&#xe640;</i>删除积分 </button></td>';
                                str += '</tr>';
                            }
                            $('#user_tbody').html(str);
                        }
                    }
                });
            });
        });


        // 增加
        function kiss_add(user) {
            window.localStorage.setItem('msg',$(user).data("id"));
            x_admin_show("编辑", "${path}/admin/creditAdd", 510,400);
        }
        // 编辑
        function kiss_edit(title, url, id, w, h) {
            x_admin_show(title, url, w, h);
        }

        function kissitem_edit(title, url, id, w, h) {
            x_admin_show(title, url, w, h);
        }

        function kissbill_edit(title, url, id, w, h) {
            x_admin_show(title, url, w, h);
        }

        function kiss_delete(user) {
            window.localStorage.setItem('msg',$(user).data("id"));
            x_admin_show("编辑", "${path}/admin/creditDelete", 510,400);
        }

    </script>
</body>

</html>